package com.wu.llpsw.event;


import com.wu.llpsw.data.levelData;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.living.LivingDamageEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
/**
 * 玩家被攻击的事件
 */
@Mod.EventBusSubscriber(modid = "wu")
public class attacked {

    //被实体攻击
    @SubscribeEvent
    public static void attackedByEntity(LivingDamageEvent event){
        if (event.getEntityLiving() instanceof Player) {
            //获取受到伤害的玩家对象
            Player player = (Player) event.getEntityLiving();
            //获取玩家受到的伤害量
            float damageAmount = event.getAmount();
            float attacked=1.0f;//自定义玩家受到的伤害量
            if(damageAmount-levelData.maxFangyuValue[levelData.getLevel(player.experienceLevel)]>=0){
                attacked=damageAmount-levelData.maxFangyuValue[levelData.getLevel(player.experienceLevel)];
            }
            else {
                attacked=0;
            }
            //可以在这里修改玩家受到的伤害量
            event.setAmount(attacked);
        }
    }


    //玩家掉落伤害
    @SubscribeEvent
    public static void onLivingFall(LivingFallEvent event) {
        if (event.getEntity() instanceof Player) {
            Player player = (Player) event.getEntity();
            float distance = event.getDistance();
            //自定义掉落高度
            float height=1.0f;
            if (distance >= 4.0f) { // 修改为你期望的掉落距离阈值
                //修改玩家掉落伤害
                event.setDistance(height);
            }
        }
    }
}
